package com.leetcode.LC;

public class LC191 {
    // you need to treat n as an unsigned value
    public int hammingWeight(int n) {
        String str = Integer.toBinaryString(n);
        int count=0;
        for (int i = 0; i < str.length(); i++) {
            if(str.charAt(i)=='1'){
                count++;
            }
        }
        return count;
    }

    public int hammingWeight2(int n) {
        int count=0;
        while (n!=0){
            count++;
            n&=(n-1);
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(new LC191().hammingWeight(11));
    }
}
